package net.minecraft.src;

import java.util.Random;

public class EntityPPHPortalFX extends EntityFX
{

	public EntityPPHPortalFX(World world, double _posX, double _posY, double _posZ, double _motionX, double _motionY, double _motionZ)
	{
		super(world, _posX, _posY, _posZ, _motionX, _motionY, _motionZ);
		motionX = _motionX;
		motionY = _motionY;
		motionZ = _motionZ;
		portalPosX = posX = _posX;
		portalPosY = posY = _posY;
		portalPosZ = posZ = _posZ;
		float f = rand.nextFloat() * 0.6F + 0.4F;
		portalParticleScale = particleScale = rand.nextFloat() * 0.2F + 0.5F;
		particleBlue = 1.0F * f * 0.3F;
		particleGreen =1.0F * f * 0.9F;
		particleRed = 1.0F * f * 0.6F;
		particleMaxAge = (int) (Math.random() * 10D) + 40;
		noClip = true;
		func_40099_c((int) (Math.random() * 8D));
	}

	public void renderParticle(Tessellator tessellator, float f, float f1, float f2, float f3, float f4, float f5)
	{
		float f6 = ((float) particleAge + f) / (float) particleMaxAge;
		f6 = 1.0F - f6;
		f6 *= f6;
		f6 = 1.0F - f6;
		particleScale = portalParticleScale * f6;
		super.renderParticle(tessellator, f, f1, f2, f3, f4, f5);
	}

	public int getEntityBrightnessForRender(float f)
	{
		int i = super.getEntityBrightnessForRender(f);
		float f1 = (float) particleAge / (float) particleMaxAge;
		f1 *= f1;
		f1 *= f1;
		int j = i & 0xff;
		int k = i >> 16 & 0xff;
		k += (int) (f1 * 15F * 16F);
		if (k > 240)
		{
			k = 240;
		}
		return j | k << 16;
	}

	public float getEntityBrightness(float f)
	{
		float f1 = super.getEntityBrightness(f);
		float f2 = (float) particleAge / (float) particleMaxAge;
		f2 *= f2;
		f2 *= f2;
		return f1 * (1.0F - f2) + f2;
	}

	public void onUpdate()
	{
		prevPosX = posX;
		prevPosY = posY;
		prevPosZ = posZ;
		float f = (float) particleAge / (float) particleMaxAge;
		float f1 = f;
		f = -f + f * f * 2.0F;
		f = 1.0F - f;
		posX = portalPosX + motionX * (double) f;
		posY = portalPosY + motionY * (double) f + (double) (1.0F - f1);
		posZ = portalPosZ + motionZ * (double) f;
		if (particleAge++ >= particleMaxAge)
		{
			setEntityDead();
		}
	}

	private float portalParticleScale;
	private double portalPosX;
	private double portalPosY;
	private double portalPosZ;
}

